package com.lee.dhsg.dao;

import com.lee.dhsg.dao.provider.TeacherSqlProvider;
import com.lee.dhsg.domain.Teacher;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Jun
 */
@Component
@Mapper
public interface TeacherDao {

	/**
	 * 查询所有教师
	 * 
	 * @return List<Teacher>
	 */
	@Select("select * from teacher")
	List<Teacher> findAll();

	/**
	 * 根据登录名和密码查询教师
	 * 
	 * @param username
	 * @param password
	 * @return Teacher
	 */
	@Select("select * from teacher where username= #{loginname} and password = #{password}")
	Teacher selectByLoginnameAndPassword(@Param("loginname") String username, @Param("password") String password);

	/**
	 * 根据id查询教师,连表查询，可以查询教师的课题
	 * @param tid
	 * @return Teacher
	 */
	@Select("select * from teacher where tid = #{tid}")
	@Results({
			@Result(id=true,column = "tid",property = "tid"),
			@Result(column = "realname",property ="realname" ),
			@Result(column = "IDCardNum" ,property ="iDCardNum" ),
			@Result(column = "IDcardImg01",property ="iDCardImg01" ),
			@Result(column = "IDCardImg02" ,property ="iDCardImg02" ),
			@Result(column = "IDCardVideo",property ="iDCardVideo" ),
			@Result(column = "username",property ="username" ),
			@Result(column = "password",property ="password" ),
			@Result(column = "sex",property ="sex" ),
			@Result(column = "icon" ,property ="icon" ),
			@Result(column = "signatrue",property ="signatrue" ),
			@Result(column = "description",property ="description" ),
			@Result(column = "tel",property ="tel" ),
			@Result(column = "email",property ="email" ),
			@Result(column = "lastlogin",property ="lastlogin" ),
			@Result(column = "realnameStatus",property ="realnameStatus" ),
			@Result(column = "checkStatus",property ="checkStatus" ),
			@Result(column = "tid",property = "courseList",
			many = @Many(
					select = "com.dhsg.dao.CourseDao.seletCourseByTid",
					fetchType = FetchType.LAZY
			))
	})
	Teacher selectByTid(Integer tid);

	/**
	 * 根据id删除教师
	 * @param tid
	 */
	@Select("delete from teacher where tid=#{tid}")
	void deleteByTid(Integer tid);
	
	/**
	 * 教师注册所需
	 * @param username
	 * @param password
	 * @return Student
	 */
		@Insert("insert into teacher(username,password) values(#{username},#{password})")
		int Signup(
                @Param("username") String username,
                @Param("password") String password);

	/**
	 * 动态查询教师
	 * @param params
	 * @return List<Teacher>
	 */
	@SelectProvider(type = TeacherSqlProvider.class, method = "selectWhitParam")
	List<Teacher> selectByPage(Map<String, Object> params);

	/**
	 * 动态插入教师，增加教师
	 * @param teacher
	 */
	@SelectProvider(type = TeacherSqlProvider.class, method = "insertTeacher")
	void saveTeacher(Teacher teacher);

	/**
	 * 动态更新教师，教师信息修改
	 * @param teacher
	 */
	@SelectProvider(type = TeacherSqlProvider.class,method = "updateTeacher")
	void updateTeacher(Teacher teacher);
}
